package platform.nettyclient.handle;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

import java.nio.charset.Charset;

public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 弃用
//        // 基于换行符号
//        socketChannel.pipeline().addLast(new LineBasedFrameDecoder(1024));
//        // 解码转String
//        socketChannel.pipeline().addLast(new StringDecoder(Charset.forName("GBK")));
//        // 解码转String
//        socketChannel.pipeline().addLast(new StringEncoder(Charset.forName("GBK")));
        // 自定义解码
        socketChannel.pipeline().addLast(new Docer());
        // 自定义编码
        socketChannel.pipeline().addLast(new MyEncoder());
        // 在管道中添加接收数据实现方法
        socketChannel.pipeline().addLast(new MyClientHandler());
    }
}
